<?php 
session_start();

header('Content-Type:application/json');
$p_name = $_POST['p_name'];
$p_detail = null;
if (isset($_POST['p_detail'])) {
	$p_detail = $_POST['p_detail'];
}


if(isset($p_name)){
	$conn = mysqli_connect('127.0.0.1','root','123456','super','3306');
	if($conn){
		mysqli_query($conn,"SET NAMES utf8");
		$sql = "INSERT INTO project(p_name,p_detail) VALUES('$p_name','$p_detail')";
		$result = mysqli_query($conn,$sql);
		$pid = mysqli_insert_id($conn);
		$uid = $_SESSION['uid'];
		$_SESSION['pid'] = $pid;
		$sql = "INSERT INTO project_user(pid,uid) VALUES($pid,$uid)";
		$result = mysqli_query($conn,$sql);
		// var_dump($pid);
		if($result){
			echo(json_encode(['success'=>true,'data'=>mysqli_insert_id($conn)]));
		}
	}else{
		echo(json_encode(['success'=>false]));
	}
}else{
	echo(json_encode(['success'=>false]));
}

// foreach ($projects as $project) {
// 	if ($project['prname']==$search) {
//  		$result = $project;
// 		break;
//  	};
 
// };
// echo(json_encode($projects));

 ?>